//package com.sky.module.suppot.file.s3;
//
//import com.amazonaws.ClientConfiguration;
//import com.amazonaws.Protocol;
//import com.amazonaws.auth.AWSCredentials;
//import com.amazonaws.auth.AWSCredentialsProvider;
//import com.amazonaws.auth.AWSStaticCredentialsProvider;
//import com.amazonaws.auth.BasicAWSCredentials;
//import com.amazonaws.client.builder.AwsClientBuilder;
//import com.amazonaws.services.s3.AmazonS3;
//import com.amazonaws.services.s3.AmazonS3Client;
//import com.amazonaws.services.s3.AmazonS3ClientBuilder;
//import com.sky.module.suppot.file.service.FileStorageService;
//import com.sky.module.suppot.file.service.impl.FileStorageServiceCloudImpl;
//import com.sky.module.suppot.file.service.impl.FileStorageServiceLocalImpl;
//import lombok.Data;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.Objects;
//import java.util.stream.Stream;
//
///**
// * 文件上传 配置
// *
// * @Author 1024创新实验室: 罗伊
// * @Date 2019-09-02 23:21:10
// * @Wechat zhuoda1024
// * @Email lab1024@163.com
// * @Copyright 1024创新实验室 （ https://1024lab.net ）
// */
//@Data
//@Configuration
//public class FileCloudConfig {
//    //#对于minio来说,配置如下
////    oss:
////    endpoint: http://minio服务器所在ip:9000
////    access-key: admin
////    access-secret: admin123
////    enable: true
//    @Value("${file.storage.cloud.region}")
//    private String region;  //1
//
//    @Value("${file.storage.cloud.endpoint}")
//    private String endpoint;  //1 http://minio服务器所在ip:9000
//
//    @Value("${file.storage.cloud.bucket-name}")
//    private String bucketName; //1
//
//    @Value("${file.storage.cloud.access-key}")
//    private String accessKey;
//
//    @Value("${file.storage.cloud.secret-key}")
//    private String secretKey;
//
//    @Value("${file.storage.cloud.url.expire}")
//    private Long urlExpire;
//
//    @Value("${file.storage.cloud.url.public}")
//    private String publicUrl;
//
//    /**
//     * 初始化 云oss client 配置
//     *
//     * @return
//     */
//    @Bean
//    @ConditionalOnProperty(prefix = "file.storage", name = {"mode"}, havingValue = "cloud")
//    public AmazonS3 initAmazonS3() {
//        long nullSize = Stream.<String>builder()
//                .add(endpoint)
//                .add(secretKey)
//                .add(accessKey)
//                .build()
//                .filter(s -> Objects.isNull(s))
//                .count();
//        if (nullSize > 0) {
//            throw new RuntimeException("oss 配置错误,请检查");
//        }
//        AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey,
//                secretKey);
//        AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
//        return AmazonS3Client.builder()
//                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region))
//                .withCredentials(awsCredentialsProvider)
//                .disableChunkedEncoding()
//                .withPathStyleAccessEnabled(true)
//                .build();
//    }
//
//    /***
//     * @description 根据条件注入我们要的对象
//     *
//     * @return com.sky.module.suppot.file.service.FileStorageService
//     * @date 2023/2/28 23:14
//     *
//     */
//    @Bean
//    @ConditionalOnProperty(prefix = "file.storage", name = {"mode"}, havingValue = "cloud")
//    public FileStorageService initCloudFileService() {
//        System.out.println("初始化FileStorageServiceCloudImpl");
//        return new FileStorageServiceCloudImpl();
//    }
//
//    @Bean
//    @ConditionalOnProperty(prefix = "file.storage", name = {"mode"}, havingValue = "local")
//    public FileStorageService initLocalFileService() {
//        System.out.println("初始化FileStorageServiceLocalImpl");
//
//        return new FileStorageServiceLocalImpl();
//    }
//
//
//}
